<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + request.getContextPath();
%>
<jsp:include page="/WEB-INF/page/auth/_header.jsp"></jsp:include>
<body>
	<jsp:include page="/WEB-INF/page/auth/header.jsp"></jsp:include>
	<div id="middle">
		<jsp:include page="/WEB-INF/page/auth/menu.jsp"></jsp:include>
		<div id="right">
		    <div id="teacher_managetb">
		        <form id="teacher_manageForm" class="mt10 ml10">
		           	 年级：
		            <select class="form-control1" name="grade" id="grade"></select>
		           	 学科：
		            <select class="form-control1" name="subjectId" id="subjectId"></select>
		                              在校状态：
		            <select class="form-control1" name="status" id="status">
		            	<option value="1">在职</option>
		            	<option value="0">离职</option>
		            </select>
		                              教师姓名：
		            <input class="form-control1" type="text" name="teacherName" id="teacherName">
					<input type="hidden" id="schoolId" name="schoolId" value=""/>
		            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-search'" onclick="searchForm('teacher_manage')">查询</a>
		            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-clear'" onclick="resetForm('teacher_manage')">重置</a><br/>
		        </form>
		    </div>
		    <table id="teacher_managedg">
		    	<thead frozen="true">
					<tr>
						<th data-options="field:'ID',checkbox:true">ID</th>
		                <th data-options="field:'name',title:'姓名'"></th>
		                <th data-options="field:'grade',title:'年级号',formatter:function(value,row,index){
		                    return row.gradeText;
		                }"></th>
		                <th data-options="field:'subjectId',title:'任教学科',sortable:true,formatter:function(value,row,index){
		                    return row.subjectText;
		                }"></th>
					</tr>
				</thead>
		        <thead>
		            <tr>
		                <th data-options="field:'idNo',title:'身份证件号'"></th>
		                <th data-options="field:'mobile',title:'手机号'"></th>
		                <th data-options="field:'sex',title:'性别'"></th>
		                <th data-options="field:'signed',title:'签到',sortable:true,formatter:function(value,row,index){
		                    if(value == 1) return '是';
		                    return '否';
		                }"></th>
		                <th data-options="field:'birthday',title:'生日'"></th>
		                <th data-options="field:'techTitle',title:'职称'"></th>
		                <th data-options="field:'nativePlace',title:'籍贯'"></th>
		                <th data-options="field:'nation',title:'民族'"></th>
		                <th data-options="field:'geopolitical',title:'政治面貌'"></th>
		                <th data-options="field:'liveAddr',title:'居住地址'"></th>
		                <th data-options="field:'partyDate',title:'入党团时间'"></th>
		                <th data-options="field:'homeNature',title:'户口性质'"></th>
		                <th data-options="field:'isMarry',title:'婚姻状况'"></th>
		                <th data-options="field:'education',title:'最高学历'"></th>
		                <th data-options="field:'workDate',title:'毕业参加工作时间'"></th>
		                <th data-options="field:'schoolMajor',title:'大学专业'"></th>
		                <th data-options="field:'isOrganTeacher',title:'是否正编教师'"></th>
		                <th data-options="field:'isChineseCard',title:'是否有普通话证'"></th>
		                <th data-options="field:'isPsychologyAbc',title:'是否具备心理ABC证'"></th>
		                <th data-options="field:'otherQualification',title:'其他获得资格证书	'"></th>
		                <th data-options="field:'hadHonor',title:'曾获得荣誉'"></th>
		            </tr>
		        </thead>
		    </table>
		</div>
	</div>
	<div id="confirmDialog" style="display: none;height: 'auto';">
		<form id="teacherDialogForm" class="easyui-form p10" method="post" data-options="novalidate:true">
	    	<input id="id" name="id" type="hidden"/>
			<input type="hidden" id="schoolId" name="schoolId" value=""/>
	    	<table cellpadding="4">
	    		<tr>
	    			<td width="10%">姓名</td>
	    			<td width="40%"><input class="easyui-textbox" type="text" name="name" id="name" data-options="required:true"></input></td>
	    			<td>最高学历</td>
	    			<td><select style="width: 150px;" class="easyui-combobox" name="education" id="education">
	    				<option value="">请选择</option>
	    				<option value="大专">大专</option>
	    				<option value="本科">本科</option>
	    				<option value="硕士">硕士</option>
	    				<option value="博士">博士</option>
	    			</select></td>
	    		</tr>
	    		<tr>
	    			<td width="10%">签到</td>
	    			<td width="40%">
	    				<select class="easyui-combobox" id="signed" name="signed" >
	    					<option value="1">是</option>
	    					<option value="0">否</option>
	    				</select>
	    			</td>
	    			<td width="10%">年级号</td>
	    			<td width="40%"><input class="easyui-combobox" name="grade" id="grade" data-options="
					url:'<%=basePath %>/gradeCombo',
					method:'get',
					panelHeight:'auto'"></td>
	    		</tr>
	    		<tr>
	    			<td>任教学科:</td>
	    			<td><input class="easyui-combobox" name="subjectId" id="subjectId" data-options="
					url:'<%=basePath %>/subjectCombo',
					method:'get'"></td>
	    			<td>身份证件号</td>
	    			<td><input class="easyui-textbox" type="text" name="idNo" id="idNo" data-options="required:true"></td>
	    		</tr>
	    		<tr>
	    			<td>手机号</td>
	    			<td><input class="easyui-numberbox" name="mobile" id="mobile" data-options="required:true"></td>
	    			<td>登录密码</td>
	    			<td><input class="easyui-passwordbox" name="password" id="password" required></td>
	    		</tr>
	    		<tr>
	    			<td>性别</td>
	    			<td><select style="width: 150px;" class="easyui-combobox" name="sex" id="sex" required>
	    				<option value="">请选择</option>
	    				<option value="男">男</option>
	    				<option value="女">女</option>
	    			</select></td>
	    			<td>出生日期</td>
	    			<td><input class="easyui-datebox" name="birthday" id="birthday"></td>
	    		</tr>
	    		<tr>
	    			<td>职称</td>
	    			<td><input class="easyui-textbox" type="text" name="techTitle" id="techTitle"></input></td>
	    			<td>籍贯</td>
	    			<td><input class="form-control1" name="nativePlace" id="nativePlace"></td>
	    		</tr>
	    		<tr>
	    			<td>民族</td>
	    			<td><select class="easyui-combobox" style="width: 150px;" name="nation" id="nation"></select></td>
	    			<td>政治面貌</td>
	    			<td><select style="width: 150px;" class="easyui-combobox" name="geopolitical" id="geopolitical">
	    				<option value="">请选择</option>
	    				<option value="男">群众</option>
	    				<option value="女">共产党员</option>
	    				<option value="女">共青团员</option>
	    				<option value="女">其它</option>
	    			</select></td>
	    		</tr>
	    		<tr>
	    			<td>居住地址</td>
	    			<td colspan="3"><input class="form-control1" name="liveAddr" id="liveAddr"> <input class="form-control1" name="liveAddrDesc" id="liveAddrDesc" style="width:250px;" placeholder="请输入居住详细地址（具体到门牌）"></td>
	    		</tr>
	    		<tr>
	    			<td>入党团时间</td>
	    			<td><input class="easyui-datebox" name="partyDate" id="partyDate"></td>
	    			<td>户口性质</td>
	    			<td><select style="width: 150px;" class="easyui-combobox" name="homeNature" id="homeNature">
	    				<option value="">请选择</option>
	    				<option value="农业">农业</option>
	    				<option value="非农业">非农业</option>
	    			</select></td>
	    		</tr>
	    		<tr>
	    			<td>婚姻状况</td>
	    			<td><select style="width: 150px;" class="easyui-combobox" name="isMarry" id="isMarry">
	    				<option value="">请选择</option>
	    				<option value="已婚">已婚</option>
	    				<option value="未婚">未婚</option>
	    				<option value="离婚">离婚</option>
	    			</select></td>
	    			<td>毕业参加工作时间</td>
	    			<td><input class="easyui-datebox" name="workDate" id="workDate"></td>
	    		</tr>
	    		<tr>
	    			<td>大学专业</td>
	    			<td><input class="easyui-textbox" type="text" name="schoolMajor" id="schoolMajor"></input></td>
	    			<td>是否正编教师</td>
	    			<td><select style="width: 150px;" class="easyui-combobox" name="isOrganTeacher" id="isOrganTeacher">
	    				<option value="">请选择</option>
	    				<option value="是">是</option>
	    				<option value="否">否</option>
	    			</select></td>
	    		</tr>
	    		<tr>
	    			<td>是否有普通话证</td>
	    			<td><select style="width: 150px;" class="easyui-combobox" name="isChineseCard" id="isChineseCard">
	    				<option value="">请选择</option>
	    				<option value="是">是</option>
	    				<option value="否">否</option>
	    			</select></td>
	    			<td>是否具备心理ABC证</td>
	    			<td><select style="width: 150px;" class="easyui-combobox" name="isPsychologyAbc" id="isPsychologyAbc">
	    				<option value="">请选择</option>
	    				<option value="是">是</option>
	    				<option value="否">否</option>
	    			</select></td>
	    		</tr>
	    		<tr>
	    			<td>其他获得资格证书</td>
	    			<td><input class="easyui-textbox" name="otherQualification" id="otherQualification" data-options="multiline:true" style="height:60px"></input></td>
	    			<td>曾获得荣誉</td>
	    			<td><input class="easyui-textbox" name="hadHonor" id="hadHonor" data-options="multiline:true" style="height:60px"></input></td>
	    		</tr>
	    	</table>
	    </form>
	</div>
	
	<div id="uploadBox" style="display: none;height: 'auto';">
	    <div class="col-md-12 pd20">
   			<form id="uploadForm" novalidate="novalidate" enctype="multipart/form-data" method="post">
				<div class="form-group col-md-12" id="scoreTips">
					
				</div>
				<div class="form-group col-md-12 mt20">
					<input class="easyui-filebox form-control" id="files" name="files" style="width:250px;">
				</div>
			</form>
		</div>
	    <div class="text-center pd20">
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadCommit()" style="width: 200px;">上传</a>
	    </div>
	</div>
	<jsp:include page="/WEB-INF/page/auth/_footer.jsp"/>
	<link rel="stylesheet" type="text/css" href="<%=basePath %>/css/weuix.min.css"/>
	<script src="<%=basePath %>/js/zepto.min.js" type="text/javascript"></script>
	<script src="<%=basePath %>/js/picker.js" type="text/javascript"></script>
    <script src="<%=basePath %>/js/picker-city.js" type="text/javascript"></script>
    <script src="<%=basePath %>/js/select.js" type="text/javascript"></script>
	<script type="text/javascript">
		var url = basePath + "/sys/teacher/manage";
        $(function(){
			initSchoolIdInputValue();
        	loadDatagrid("teacher_manage",url);
            initGrade("teacher_manage");
            initSubject("teacher_manage");
            $('#files').filebox({
                buttonText: '选择文件',
                buttonAlign: 'left'
            });
            $("#nativePlace").cityPicker({
    	        title: "请选择省市区"
    	    });
    	    $("#liveAddr").cityPicker({
    	        title: "请选择省市区"
    	    });
        });
		function initSchoolIdInputValue() {
			var schoolId = $("#userSchoolId").val();
			$("#teacher_manageForm #schoolId").val(schoolId);
			$("#teacherDialogForm #schoolId").val(schoolId);
		}
        initNation("teacherDialog");
        function loadDatagrid(cf, url) {
        	var btnArr=[];
			btnArr.push({text:'增加',iconCls:'icon-add',handler:function(){
				addTeacher();	       
			}},'-');
			btnArr.push({text:'删除',iconCls:'icon-remove',handler:function(){
				del(cf, url);
			}},'-');
			btnArr.push({text:'修改',iconCls:'icon-edit',handler:function(){
				var dgObj=$('#teacher_managedg');
				var rows=dgObj.datagrid('getSelections');
				if(rows.length == 0) return;
				updateTeachequeryById(rows[0].id);
			}},'-');
			btnArr.push({text:'下载EXCEL模板',iconCls:'icon-save',handler:function(){downloadTemplate('教师信息采集模板.xls')}},"-");
			btnArr.push({text:'导入',iconCls:'icon-large-smartart',handler:function(){upload()}},"-");
			btnArr.push({text:'导出名单',iconCls:'icon-save',handler:function(){exportExcel(cf,url+'/export')}});
			$("#teacher_managedg").datagrid({
				url: url + "/pageQuery",
				rownumbers: true,
				striped: true,
				border: false,
				pagination: true,
				pageSize: 30,
				fitColumns: true,
				autoRowHeight: false,
				singleSelect: true,
				fit: true,
				toolbar: btnArr,
				queryParams : {
					schoolId: $("#userSchoolId").val()
				}
			});
			var tb = $("#"+cf+"tb").html();
			if(tb) {
				$(".datagrid-toolbar").prepend(tb);
				$("#"+cf+"tb").remove();
			}
		}
        function addTeacher() {
        	loadForm();
        }
        function updateTeacher(id) {
       		$.ajax({
       	 		url : url + "/queryById/" + id,
       	 		type : "GET",
       	 		dataType : "json",
       	 		async : false,
       	 		success : function(data) {
       	 			loadForm(1);
	       	 		$('#teacherDialogForm #id').val(id);
	   	 			$('#teacherDialogForm #name').textbox("setValue", data.name);
	   	 			$('#teacherDialogForm #education').combobox("setValue", data.education);
	   	 			$('#teacherDialogForm #idNo').textbox("setValue", data.idNo);
	   	 			$('#teacherDialogForm #password').passwordbox("setValue", data.password);
	   	 			$('#teacherDialogForm #mobile').textbox("setValue", data.mobile);
	   	 			$('#teacherDialogForm #birthday').textbox("setValue", data.birthday);
	   	 			$('#teacherDialogForm #techTitle').textbox("setValue", data.techTitle);
	       	 		$('#teacherDialogForm #nativePlace').val(data.nativePlace);
	   	 			$('#teacherDialogForm #partyDate').textbox("setValue", data.partyDate);
	   	 			$('#teacherDialogForm #workDate').textbox("setValue", data.workDate);
	   	 			$('#teacherDialogForm #schoolMajor').textbox("setValue", data.schoolMajor);
	   	 			$('#teacherDialogForm #otherQualification').textbox("setValue", data.otherQualification);
		 			$('#teacherDialogForm #hadHonor').textbox("setValue", data.hadHonor);
		 			$('#teacherDialogForm #grade').combobox("setValue", data.grade);
		 			$('#teacherDialogForm #signed').combobox("setValue", data.signed);
		 			$('#teacherDialogForm #subjectId').combobox("setValue", data.subjectId);
	       	 		$('#teacherDialogForm #sex').combobox("setValue", data.sex);
	    			$('#teacherDialogForm #nation').combobox("setValue", data.nation);
	    			$('#teacherDialogForm #geopolitical').combobox("setValue", data.geopolitical);
	    			$('#teacherDialogForm #homeNature').combobox("setValue", data.homeNature);
	    			$('#teacherDialogForm #isMarry').combobox("setValue", data.isMarry);
	    			$('#teacherDialogForm #isOrganTeacher').combobox("setValue", data.isOrganTeacher);
	    			$('#teacherDialogForm #isChineseCard').combobox("setValue", data.isChineseCard);
	    			$('#teacherDialogForm #isPsychologyAbc').combobox("setValue", data.isPsychologyAbc);
	    			initLiveAddr(data.liveAddr);
       	 		}
       	 	});
        }
        function resetForms(){
        	$('#teacherDialogForm #id').val(null);
 			$('#teacherDialogForm #name').textbox("setValue", null);
 			$('#teacherDialogForm #education').combobox("setValue", null);
 			$('#teacherDialogForm #idNo').textbox("setValue", null);
 			$('#teacherDialogForm #password').passwordbox("setValue", null);
 			$('#teacherDialogForm #mobile').textbox("setValue", null);
 			$('#teacherDialogForm #birthday').textbox("setValue", null);
 			$('#teacherDialogForm #techTitle').textbox("setValue", null);
   	 		$('#teacherDialogForm #nativePlace').val(null);
 			$('#teacherDialogForm #partyDate').textbox("setValue", null);
 			$('#teacherDialogForm #workDate').textbox("setValue", null);
 			$('#teacherDialogForm #schoolMajor').textbox("setValue", null);
 			$('#teacherDialogForm #otherQualification').textbox("setValue", null);
 			$('#teacherDialogForm #hadHonor').textbox("setValue", null);
 			$('#teacherDialogForm #grade').combobox("setValue", null);
 			$('#teacherDialogForm #signed').combobox("setValue", null);
 			$('#teacherDialogForm #subjectId').combobox("setValue", null);
   	 		$('#teacherDialogForm #sex').combobox("setValue", null);
			$('#teacherDialogForm #nation').combobox("setValue", null);
			$('#teacherDialogForm #geopolitical').combobox("setValue", null);
			$('#teacherDialogForm #homeNature').combobox("setValue", null);
			$('#teacherDialogForm #isMarry').combobox("setValue", null);
			$('#teacherDialogForm #isOrganTeacher').combobox("setValue", null);
			$('#teacherDialogForm #isChineseCard').combobox("setValue", null);
			$('#teacherDialogForm #isPsychologyAbc').combobox("setValue", null);
			$("#liveAddr").val(null);
			$("#liveAddrDesc").val(null);
        }
	    function initLiveAddr(v) {
			if(!v) return;
			var array = v.split(",");
			$("#liveAddr").val(array[0]);
			$("#liveAddrDesc").val(array[1]);
		}
        var loadForm = function(data){
        	confirmDialog = $('#confirmDialog').dialog({
        		title : data != null ? "修改教师信息" : "新增教师",
        		modal : true,
        		width : 800,
        		height: 600,
        		top : 60,
        		left: 220,
        		draggable : true,
        		resizable : true,
        		buttons : [{
					text:'确认',
					iconCls:'icon-ok',
					handler:function(){
						submitForm();
					}
				},{
					text:'取消',
					iconCls:'icon-cancel',
					handler:function(){
						$('#confirmDialog').dialog("close");
					}
				}],
        		onClose : function() {
        			resetForms();
        		}
        	}).show();
        }
        
        function submitForm() {
			var data = $.serializeObject($("#teacherDialogForm"));
			if(!data.name) {
				$.messager.alert('提醒','姓名不能为空','info');
				return false;
			}
			else if(!data.idNo) {
				$.messager.alert('提醒','姓名不能为空','info');
				return false;
			}
			else if(!data.password) {
				$.messager.alert('提醒','登录密码不能为空','info');
				return false;
			}
			else if(!data.sex) {
				$.messager.alert('提醒','请选择性别','info');
				return false;
			}
			else if(!data.mobile) {
				$.messager.alert('提醒','联系不能为空','info');
				return false;
			}
			if(data.liveAddr && data.liveAddrDesc) {
				data.liveAddr += "," + data.liveAddrDesc;
			}else {
				if(data.liveAddr || data.liveAddrDesc) {
					$.messager.alert('提醒','居住地址填写完整','info');
					return false;
				}
			}
			$.ajax({
				url: basePath + "/sys/teacher/manage/addUpdate",
				type: 'POST',
				data: data
			}).done(function(data) {
				if(data.code=='000'){
					$.messager.show({title:'操作提示', msg:"提交成功"});
					$('#confirmDialog').dialog("close");
					$('#teacher_managedg').datagrid('reload');
				}
			}).fail(function() {
				$('#msg').html('error,发生错误请及时联系管理员!');
			});
		}
        
        var uploadBox;
        function upload() {
        	$("#scoreTips").html("<span class='calendar-sunday'>确认信息无误？以免上传出错</span>");
        	uploadBox = $('#uploadBox').dialog({
        		title : '上传学生信息',
        		modal : true,
        		width : 400,
        		top : 200,
        		draggable : true,
        		resizable : true,
        		buttons : '#btns',
        		onClose : function() {
        			$('#files').filebox('setValue','');
        		}
        	}).show();
        }

        function uploadCommit(){
        	var fileObj = document.getElementById('filebox_file_id_2').files[0];
        	if(!fileObj) {
        		$.messager.alert('提醒','请选择文件');
        		return;
        	}
        	$.messager.progress({
        		title : '提示',
        		msg : '上传中，请稍候...'
        	});
        	var xhr = new XMLHttpRequest();
        	xhr.open('POST', basePath + "/sys/report/teacher/import");
        	xhr.onload = function () {
               if (xhr.status === 200) {
            	    $.messager.progress('close');
        	       	var resp = JSON.parse(xhr.response);
        	       	if(resp.code == '000') {
        	       		$.messager.alert("成功","上传成功！","info");
        	       		$('#teacher_managedg').datagrid('reload');
        	       		$('#files').filebox('setValue','');
        	       		uploadBox.dialog('close');
        	       	}else {
        	       		$.messager.alert('错误提醒', resp.msg);
        	       	}
               }
           };
           xhr.onerror = function () {
        	   $.messager.progress('close');
        	   $.messager.alert('错误', "上传异常");
           };
           var fd = new FormData();
           fd.append('files', fileObj);
           // 触发上传
        	setTimeout(function() {
        		xhr.send(fd);
        	}, 1000)
        }
    </script>
</body>
</html>